//package cn.pfz.interceptor;
//
//import cn.pfz.annotation.RequiredPermission;
//import cn.pfz.domain.Permission;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.method.HandlerMethod;
//import org.springframework.web.servlet.HandlerInterceptor;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.ArrayList;
//import java.util.List;
//
//
//public class MypermissionInterceptor implements HandlerInterceptor {
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        System.out.println("我是sb");
//
//        List<Permission> userpermission = (List<Permission>) request.getSession().getAttribute("userpermission");
//        List<String> arrayList = new ArrayList();
//        if (userpermission != null) {
//            for (Permission permission : userpermission) {
//                arrayList.add(permission.getExpression());
//            }
//        }else
//        {
//            response.sendRedirect("http://localhost:8080/erro/abc");
//
//            return false;
//        }
//
//        if (!(handler instanceof HandlerMethod)) {
//            return true;
//        }
//        HandlerMethod handlerMethod = (HandlerMethod) handler;
//        RequiredPermission methodAnnotation = handlerMethod.getMethodAnnotation(RequiredPermission.class);
//        if (methodAnnotation == null) {
//            return true;
//        } else {
//            //得到表达式
//            String experssion = methodAnnotation.experssion();
//            if (arrayList.contains(experssion)) {
//                return true;
//            }else {
//                response.sendRedirect("http://localhost:8080/erro/cba");
//                return false;
//            }
//
//        }
//
//    }
//
//    @Override
//    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
//        HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
//    }
//
//    @Override
//    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
//        HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
//    }
//
//}
